package com.apache.funds.service.plugins;

import java.util.Map;

import net.sf.json.JSONObject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.apache.api.manager.PluginConnector;
import com.apache.api.vo.ParamsVo;
import com.apache.api.vo.ResultEntity;
import com.apache.cache.util.Validator;
import com.apache.funds.entity.SvmUser;
import com.apache.funds.manager.SvmUserManager;
import com.apache.funds.util.Constants;

/**  
 * 查询我的虚拟账户信息（根据createUserEname登录账号查询）
 * @author xhe 创建时间：2016-10-26      
 */
public class FundsMyAccountByCreateUserEnamePlugin implements PluginConnector {
	private Logger log = LoggerFactory.getLogger(getClass());
	private SvmUserManager svmUserManager;

	@SuppressWarnings("unchecked")
	@Override
	public Object execute(ParamsVo pvo) throws Exception {
		ResultEntity entity = new ResultEntity();
		entity.setResult("true");
		entity.setMessage("查询失败");

		Map<String, String> prarmMap = pvo.getParams();
		//校验参数
		String createUserEname = prarmMap.get("createUserEname");//一般是UCT用户的userEname登录号
		if (Validator.isNull(createUserEname)) {
			entity.setMessage(Constants.Msg.F006);
			return entity;
		}
		ParamsVo<SvmUser> voU = new ParamsVo<SvmUser>();
		voU.setParams("createUserEname", createUserEname);
		voU.setMethodKey("ByCreateUserEname");
		SvmUser selectUser = (SvmUser) svmUserManager.execute(voU);
		if (selectUser == null) {
			log.info("此[" + createUserEname + "]未开通虚拟账户");
			entity.setMessage(Constants.Msg.F004);
			return entity;
		}
		entity.setMessage(Constants.Msg.F000+",查询完成");
		entity.setEntity(JSONObject.fromObject(selectUser));
		return entity;
	}

	public void setSvmUserManager(SvmUserManager svmUserManager) {
		this.svmUserManager = svmUserManager;
	}

}
